import QtQuick 2.0

Item {
    id: turnLight
    width: 320
    height: 180

    property bool isLeft: true
    property int tindex: isLeft?2:0
    property int shaRate: 500
    property bool isRuning: true
    visible: isLeft ? loader_can.turn_left_light: loader_can.turn_right_light

//    Row{
//        Repeater{
//            id: lightRepeater
//            model: isLeft ? ["1", "2", "3"] : ["3", "2", "1"]
//            delegate: Image{
//                id: icon
//                visible: true
//                source: "qrc:/imgs/digger_arrow_" + modelData + ".png"
//                anchors.verticalCenter: parent.verticalCenter
//                scale: isLeft?1:-1


//                Connections{
//                    target: turnLight
//                    function  onTindexChanged() {
//                        visible = index == tindex ? false : true
//                    }
//                }
//            }
//        }
//    }

//    Image {
//        id: img1
//        visible: false
//        scale: isLeft?1:-1
//        fillMode: Image.PreserveAspectFit
//        source: isLeft ? "qrc:/imgs/digger_arrow_1.png" : "qrc:/imgs/digger_arrow_3.png"
//        Connections{
//            target: turnLight
//            function  onTindexChanged() {
//                img1.visible = 0 == tindex ? true : false
//            }
//        }
//    }

//    Image {
//        id: img2
//        visible: false
//        anchors.left: img1.right
//        scale: isLeft?1:-1
//        fillMode: Image.PreserveAspectFit
//        source: "qrc:/imgs/digger_arrow_2.png"
//        Connections{
//            target: turnLight
//            function  onTindexChanged() {
//                img2.visible = 1 == tindex ? true : false
//            }
//        }
//    }

//    Image {
//        id: img3
//        visible: false
//        anchors.left: img2.right
//        scale: isLeft?1:-1
//        fillMode: Image.PreserveAspectFit
//        source: isLeft ? "qrc:/imgs/digger_arrow_3.png" : "qrc:/imgs/digger_arrow_1.png"
//        Connections{
//            target: turnLight
//            function  onTindexChanged() {
//                img3.visible = 2 == tindex ? true : false
//            }
//        }
//    }

//    Timer{
//        id: lightTime
//        interval: shaRate
//        running: true
//        repeat: true
//        onTriggered: {
//            if(isLeft){
//                tindex -= 1
//                if(tindex == -1){
//                    tindex = 2
//                }
//            }else{
//                tindex += 1
//                if(tindex == 3){
//                    tindex = 0
//                }
//            }
//        }
//    }

    Image {
        id: img1
        x: 0
        anchors.verticalCenter: parent.verticalCenter
        width: 120
        height: 180
        scale: isLeft ? 1 : -1
        source: isLeft ? "qrc:/imgs/digger_arrow_1.png" : "qrc:/imgs/digger_arrow_3.png"
        NumberAnimation on x {
            id: imgAn1
            to: isLeft ? -120 : 480
            duration: isLeft ? 500 : 1500
            running: isRuning
        }
        onXChanged: {
            if (x == imgAn1.to){
                x = isLeft ? turnLight.width : 0
                imgAn1.duration = 1500
                imgAn1.restart()
            }
        }
    }

    Image {
        id: img2
        x: 120
        anchors.verticalCenter: parent.verticalCenter
        width: 120
        height: 180
        scale: isLeft ? 1 : -1
        fillMode: Image.PreserveAspectFit
        source: "qrc:/imgs/digger_arrow_2.png"
        NumberAnimation on x {
            id: imgAn2
            running: isRuning
            to: isLeft ? -120 : 480
            duration: 1000
        }
        onXChanged: {
            if (x == imgAn2.to){
                x = isLeft ? turnLight.width : 0
                imgAn2.duration = 1500
                imgAn2.restart()
            }
        }
    }

    Image {
        id: img3
        x: 240
        anchors.verticalCenter: parent.verticalCenter
        width: 120
        height: 180
        scale: isLeft ? 1 : -1
        source: isLeft ? "qrc:/imgs/digger_arrow_3.png" : "qrc:/imgs/digger_arrow_1.png"
        NumberAnimation on x {
            id: imgAn3
            running: isRuning
            to: isLeft ? -120 : 480
            duration: isLeft ? 1500 : 500
        }
        onXChanged: {
            if (x == imgAn3.to){
                x = isLeft ? turnLight.width : 0
                imgAn3.duration = 1500
                imgAn3.restart()
            }
        }
    }
}
